GdiPlusHeaders.h revision ee451cb395940862dad63c85adfe8f2fd55e864c
1/**************************************************************************\
2*
3* Copyright (c) 1998-2000, Microsoft Corp.  All Rights Reserved.
4*
5* Module Name:
6*
7*   GdiplusHeaders.h
8*
9* Abstract:
10*
11*   GDI+ Native C++ public header file
12*
13\**************************************************************************/
14
15#ifndef _GDIPLUSHEADERS_H
16#define _GDIPLUSHEADERS_H
17
18//--------------------------------------------------------------------------
19// Abstract base class for regions
20//--------------------------------------------------------------------------
21
22//  Include the class declarations here and have inline class implementation
23//  in separate file to avoid circular references.
24
25class Region : public GdiplusBase
26{
27public:
28    friend class Graphics;
29
30    Region();
31    Region(IN const RectF& rect);
32    Region(IN const Rect& rect);
33    Region(IN const GraphicsPath* path);
34    Region(IN const BYTE* regionData, IN INT size);
35    Region(IN HRGN hRgn);
36    static Region* FromHRGN(IN HRGN hRgn);
37
38    ~Region();
39    Region* Clone() const;
40
41    Status MakeInfinite();
42    Status MakeEmpty();
43
44    // Get the size of the buffer needed for the GetData method
45    UINT GetDataSize() const;
46
47    // buffer     - where to put the data
48    // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
49    // sizeFilled - if not NULL, this is an OUT param that says how many bytes
50    //              of data were written to the buffer.
51    Status GetData(OUT BYTE* buffer,
52                   IN UINT bufferSize,
53                   OUT UINT* sizeFilled = NULL) const;
54
55    Status Intersect(IN const Rect& rect);
56    Status Intersect(IN const RectF& rect);
57    Status Intersect(IN const GraphicsPath* path);
58    Status Intersect(IN const Region* region);
59    Status Union(IN const Rect& rect);
60    Status Union(IN const RectF& rect);
61    Status Union(IN const GraphicsPath* path);
62    Status Union(IN const Region* region);
63    Status Xor(IN const Rect& rect);
64    Status Xor(IN const RectF& rect);
65    Status Xor(IN const GraphicsPath* path);
66    Status Xor(IN const Region* region);
67    Status Exclude(IN const Rect& rect);
68    Status Exclude(IN const RectF& rect);
69    Status Exclude(IN const GraphicsPath* path);
70    Status Exclude(IN const Region* region);
71    Status Complement(IN const Rect& rect);
72    Status Complement(IN const RectF& rect);
73    Status Complement(IN const GraphicsPath* path);
74    Status Complement(IN const Region* region);
75    Status Translate(IN REAL dx,
76                     IN REAL dy);
77    Status Translate(IN INT dx,
78                     IN INT dy);
79    Status Transform(IN const Matrix* matrix);
80
81    Status GetBounds(OUT Rect* rect,
82                     IN const Graphics* g) const;
83
84    Status GetBounds(OUT RectF* rect,
85                     IN const Graphics* g) const;
86
87    HRGN   GetHRGN  (IN const Graphics * g) const;
88
89    BOOL IsEmpty(IN const Graphics *g) const;
90    BOOL IsInfinite(IN const Graphics *g) const;
91
92    BOOL IsVisible(IN INT x,
93                   IN INT y,
94                   IN const Graphics* g = NULL) const
95    {
96        return IsVisible(Point(x, y), g);
97    }
98
99    BOOL IsVisible(IN const Point& point,
100                   IN const Graphics* g = NULL) const;
101
102    BOOL IsVisible(IN REAL x,
103                   IN REAL y,
104                   IN const Graphics* g = NULL) const
105    {
106        return IsVisible(PointF(x, y), g);
107    }
108
109    BOOL IsVisible(IN const PointF& point,
110                   IN const Graphics* g = NULL) const;
111
112    BOOL IsVisible(IN INT x,
113                   IN INT y,
114                   IN INT width,
115                   IN INT height,
116                   IN const Graphics* g) const
117    {
118        return IsVisible(Rect(x, y, width, height), g);
119    }
120
121    BOOL IsVisible(IN const Rect& rect,
122                   IN const Graphics* g = NULL) const;
123
124    BOOL IsVisible(IN REAL x,
125                   IN REAL y,
126                   IN REAL width,
127                   IN REAL height,
128                   IN const Graphics* g = NULL) const
129    {
130        return IsVisible(RectF(x, y, width, height), g);
131    }
132
133    BOOL IsVisible(IN const RectF& rect,
134                   IN const Graphics* g = NULL) const;
135
136    BOOL Equals(IN const Region* region,
137                IN const Graphics* g) const;
138
139    UINT GetRegionScansCount(IN const Matrix* matrix) const;
140    Status GetRegionScans(IN const Matrix* matrix,
141                          OUT RectF* rects,
142                          OUT INT* count) const;
143    Status GetRegionScans(IN const Matrix* matrix,
144                          OUT Rect*  rects,
145                          OUT INT* count) const;
146    Status GetLastStatus() const;
147
148protected:
149
150#ifdef DCR_USE_NEW_250932
151
152private:
153    Region(const Region &region);
154    Region& operator=(const Region &region);
155protected:
156
157#else
158    Region(const Region &region)
159    {
160        region; // reference parameter
161        SetStatus(NotImplemented);
162    }
163
164    Region& operator=(const Region &region)
165    {
166       region;  // reference parameter
167       SetStatus(NotImplemented);
168       return *this;
169    }
170#endif
171
172    Status SetStatus(Status status) const
173    {
174        if (status != Ok)
175            return (lastResult = status);
176        else
177            return status;
178    }
179
180    Region(GpRegion* nativeRegion);
181
182    VOID SetNativeRegion(GpRegion* nativeRegion);
183
184protected:
185    GpRegion* nativeRegion;
186    mutable Status lastResult;
187};
188
189
190//--------------------------------------------------------------------------
191// Abstract base class for FontFamily
192//--------------------------------------------------------------------------
193
194class FontFamily : public GdiplusBase
195{
196public:
197    friend class Font;
198    friend class Graphics;
199    friend class GraphicsPath;
200    friend class FontCollection;
201
202    FontFamily();
203
204    FontFamily(
205        IN const WCHAR          *name,
206        IN const FontCollection *fontCollection = NULL
207    );
208
209    ~FontFamily();
210
211    static const FontFamily *GenericSansSerif();
212    static const FontFamily *GenericSerif();
213    static const FontFamily *GenericMonospace();
214
215    Status GetFamilyName(
216        OUT WCHAR        name[LF_FACESIZE],
217        IN LANGID        language = 0
218    ) const;
219
220//  Copy operator
221    FontFamily * Clone() const;
222
223    BOOL    IsAvailable() const
224    {
225        return (nativeFamily != NULL);
226    };
227
228    BOOL    IsStyleAvailable(IN INT style) const;
229
230    UINT16  GetEmHeight     (IN INT style) const;
231    UINT16  GetCellAscent   (IN INT style) const;
232    UINT16  GetCellDescent  (IN INT style) const;
233    UINT16  GetLineSpacing  (IN INT style) const;
234
235    ///////////////////////////////////////////////////////////
236
237    Status GetLastStatus() const;
238
239#ifdef DCR_USE_NEW_250932
240
241private:
242    FontFamily(const FontFamily &);
243    FontFamily& operator=(const FontFamily &);
244
245#endif
246
247protected:
248    Status SetStatus(Status status) const;
249
250    // private constructor for copy
251    FontFamily(GpFontFamily * nativeFamily, Status status);
252
253///////////////////////////////////////
254//  Data members
255protected:
256
257    GpFontFamily    *nativeFamily;
258    mutable Status   lastResult;
259};
260
261static FontFamily *GenericSansSerifFontFamily = NULL;
262static FontFamily *GenericSerifFontFamily     = NULL;
263static FontFamily *GenericMonospaceFontFamily = NULL;
264
265static BYTE GenericSansSerifFontFamilyBuffer[sizeof(FontFamily)] = {0};
266static BYTE GenericSerifFontFamilyBuffer    [sizeof(FontFamily)] = {0};
267static BYTE GenericMonospaceFontFamilyBuffer[sizeof(FontFamily)] = {0};
268
269
270//--------------------------------------------------------------------------
271// Abstract base class for fonts
272//--------------------------------------------------------------------------
273
274class Font : public GdiplusBase
275{
276public:
277    friend class Graphics;
278
279    Font(IN HDC hdc);
280    Font(IN HDC hdc,
281         IN const LOGFONTA* logfont);
282    Font(IN HDC hdc,
283         IN const LOGFONTW* logfont);
284#ifdef DCR_USE_NEW_127084
285    Font(IN HDC hdc,
286         IN const HFONT hfont);
287#endif
288    Font(
289        IN const FontFamily * family,
290        IN REAL         emSize,
291        IN INT          style   = FontStyleRegular,
292        IN Unit         unit    = UnitPoint
293    );
294
295    Font(
296        IN const WCHAR *           familyName,
297        IN REAL                    emSize,
298        IN INT                     style   = FontStyleRegular,
299        IN Unit                    unit    = UnitPoint,
300        IN const FontCollection *  fontCollection = NULL
301    );
302
303    Status GetLogFontA(IN const Graphics* g,
304                       OUT  LOGFONTA * logfontA) const;
305    Status GetLogFontW(IN const Graphics* g,
306                       OUT LOGFONTW * logfontW) const;
307
308    Font* Clone() const;
309    ~Font();
310    BOOL        IsAvailable()   const;
311    INT         GetStyle()      const;
312    REAL        GetSize()       const;
313    Unit        GetUnit()       const;
314    Status      GetLastStatus() const;
315    REAL        GetHeight(IN const Graphics *graphics = NULL) const;
316#ifdef DCR_USE_NEW_125467
317    REAL        GetHeight(IN REAL dpi) const;
318#endif
319
320    Status GetFamily(OUT FontFamily *family) const;
321
322#ifdef DCR_USE_NEW_250932
323
324private:
325    Font(const Font &);
326    Font& operator=(const Font &);
327
328#endif
329
330protected:
331    Font(GpFont* font, Status status);
332    VOID SetNativeFont(GpFont *Font);
333    Status SetStatus(Status status) const;
334
335protected:
336    /*
337     * handle to native line texture object
338     */
339
340    GpFont* nativeFont;
341    mutable Status lastResult;
342};
343
344//--------------------------------------------------------------------------
345// Abstract base classes for font collections
346//--------------------------------------------------------------------------
347
348class FontCollection : public GdiplusBase
349{
350public:
351    friend class FontFamily;
352
353    FontCollection();
354    virtual ~FontCollection();
355
356    INT GetFamilyCount() const;     // number of enumerable families in the collection
357
358    Status GetFamilies(             // enumerate the fonts in a collection
359        IN INT           numSought,
360        OUT FontFamily * gpfamilies,
361        OUT INT        * numFound
362    ) const;
363
364    Status GetLastStatus() const;
365
366#ifdef DCR_USE_NEW_250932
367
368private:
369    FontCollection(const FontCollection &);
370    FontCollection& operator=(const FontCollection &);
371
372#endif
373
374protected:
375    Status SetStatus(Status status) const ;
376
377    GpFontCollection *nativeFontCollection;
378    mutable Status    lastResult;
379};
380
381
382class InstalledFontCollection : public FontCollection
383{
384public:
385    InstalledFontCollection();
386    ~InstalledFontCollection();
387
388#ifdef DCR_USE_NEW_250932
389
390private:
391    InstalledFontCollection(const InstalledFontCollection &);
392    InstalledFontCollection& operator=(const InstalledFontCollection &);
393
394#endif
395
396protected:
397#ifndef DCR_USE_NEW_235072
398    Status InstallFontFile(IN const WCHAR* filename);
399    Status UninstallFontFile(IN const WCHAR* filename);
400#endif
401    Status SetStatus(Status status) const ;
402};
403
404
405class PrivateFontCollection : public FontCollection
406{
407public:
408    PrivateFontCollection();
409    ~PrivateFontCollection();
410
411    Status AddFontFile(IN const WCHAR* filename);
412    Status AddMemoryFont(IN const VOID* memory,
413                         IN INT length);
414
415#ifdef DCR_USE_NEW_250932
416
417private:
418    PrivateFontCollection(const PrivateFontCollection &);
419    PrivateFontCollection& operator=(const PrivateFontCollection &);
420
421#endif
422};
423
424
425//--------------------------------------------------------------------------
426// Abstract base class for bitmap image and metafile
427//--------------------------------------------------------------------------
428
429// !!! Note:
430//  Include the class declarations here and have the inline class
431//  implementation in a separate file.  This is done to resolve a
432//  circular dependency since one of the Bitmap methods needs to
433//  access the private member nativeGraphics of the Graphics object.
434
435class Image : public GdiplusBase
436{
437public:
438    friend class Brush;
439    friend class TextureBrush;
440    friend class Graphics;
441
442#ifndef DCR_USE_NEW_140782
443    Image(
444        IN const WCHAR* filename
445    );
446
447    Image(
448        IN IStream* stream
449    );
450
451    static Image* FromFile(
452        IN const WCHAR* filename
453    );
454
455    static Image* FromStream(
456        IN IStream* stream
457    );
458#else
459    Image(
460        IN const WCHAR* filename,
461        IN BOOL useEmbeddedColorManagement = FALSE
462    );
463
464    Image(
465        IN IStream* stream,
466        IN BOOL useEmbeddedColorManagement = FALSE
467    );
468
469    static Image* FromFile(
470        IN const WCHAR* filename,
471        IN BOOL useEmbeddedColorManagement = FALSE
472    );
473
474    static Image* FromStream(
475        IN IStream* stream,
476        IN BOOL useEmbeddedColorManagement = FALSE
477    );
478#endif
479
480    virtual ~Image();
481    virtual Image* Clone();
482
483    Status Save(IN const WCHAR* filename,
484                IN const CLSID* clsidEncoder,
485                IN const EncoderParameters *encoderParams = NULL);
486    Status Save(IN IStream* stream,
487                IN const CLSID* clsidEncoder,
488                IN const EncoderParameters *encoderParams = NULL);
489    Status SaveAdd(IN const EncoderParameters* encoderParams);
490    Status SaveAdd(IN Image* newImage,
491                   IN const EncoderParameters* encoderParams);
492
493    ImageType GetType() const;
494    Status GetPhysicalDimension(OUT SizeF* size);
495    Status GetBounds(OUT RectF* srcRect,
496                     OUT Unit* srcUnit);
497
498    UINT GetWidth();
499    UINT GetHeight();
500    REAL GetHorizontalResolution();
501    REAL GetVerticalResolution();
502    UINT GetFlags();
503    Status GetRawFormat(OUT GUID *format);
504    PixelFormat GetPixelFormat();
505
506    INT GetPaletteSize();
507    Status GetPalette(OUT ColorPalette* palette,
508                      IN INT size);
509    Status SetPalette(IN const ColorPalette* palette);
510
511    Image* GetThumbnailImage(IN UINT thumbWidth,
512                             IN UINT thumbHeight,
513                             IN GetThumbnailImageAbort callback = NULL,
514                             IN VOID* callbackData = NULL);
515    UINT GetFrameDimensionsCount();
516    Status GetFrameDimensionsList(OUT GUID* dimensionIDs,
517                                  IN UINT count);
518    UINT GetFrameCount(IN const GUID* dimensionID);
519    Status SelectActiveFrame(IN const GUID* dimensionID,
520                             IN UINT frameIndex);
521    Status RotateFlip(IN RotateFlipType rotateFlipType);
522    UINT GetPropertyCount();
523    Status GetPropertyIdList(IN UINT numOfProperty,
524                             OUT PROPID* list);
525    UINT GetPropertyItemSize(IN PROPID propId);
526    Status GetPropertyItem(IN PROPID propId,
527                           IN UINT propSize,
528                           OUT PropertyItem* buffer);
529    Status GetPropertySize(OUT UINT* totalBufferSize,
530                           OUT UINT* numProperties);
531    Status GetAllPropertyItems(IN UINT totalBufferSize,
532                               IN UINT numProperties,
533                               OUT PropertyItem* allItems);
534    Status RemovePropertyItem(IN PROPID propId);
535    Status SetPropertyItem(IN const PropertyItem* item);
536
537    UINT  GetEncoderParameterListSize(IN const CLSID* clsidEncoder);
538    Status GetEncoderParameterList(IN const CLSID* clsidEncoder,
539                                   IN UINT size,
540                                   OUT EncoderParameters* buffer);
541
542    // Support for Middle East localization (right-to-left mirroring)
543    ImageLayout GetLayout() const;
544    Status SetLayout(IN const ImageLayout layout);
545
546    Status GetLastStatus() const;
547
548protected:
549
550    Image() {}
551
552    Image(GpImage *nativeImage, Status status);
553
554    VOID SetNativeImage(GpImage* nativeImage);
555
556    Status SetStatus(Status status) const
557    {
558        if (status != Ok)
559            return (lastResult = status);
560        else
561            return status;
562    }
563
564    GpImage* nativeImage;
565    mutable Status lastResult;
566    mutable Status loadStatus;
567
568#ifdef DCR_USE_NEW_250932
569
570private:
571
572#else
573
574protected:
575
576#endif
577
578    // Disable copy constructor and assignment operator
579
580    Image(IN const Image& C);
581    Image& operator=(IN const Image& C);
582};
583
584class Bitmap : public Image
585{
586public:
587    friend class Image;
588    friend class CachedBitmap;
589
590    Bitmap(
591        IN const WCHAR *filename,
592        IN BOOL useEmbeddedColorManagement = FALSE
593    );
594
595    Bitmap(
596        IN IStream *stream,
597        IN BOOL useEmbeddedColorManagement = FALSE
598    );
599
600    static Bitmap* FromFile(
601        IN const WCHAR *filename,
602        IN BOOL useEmbeddedColorManagement = FALSE
603    );
604
605    static Bitmap* FromStream(
606        IN IStream *stream,
607        IN BOOL useEmbeddedColorManagement = FALSE
608    );
609
610    Bitmap(IN INT width,
611           IN INT height,
612           IN INT stride, PixelFormat format,
613           IN BYTE* scan0);
614    Bitmap(IN INT width,
615           IN INT height,
616           IN PixelFormat format = PixelFormat32bppARGB);
617    Bitmap(IN INT width,
618           IN INT height,
619           IN  Graphics* target);
620
621    Bitmap* Clone(IN const Rect& rect,
622                  IN PixelFormat format);
623    Bitmap* Clone(IN INT x,
624                  IN INT y,
625                  IN INT width,
626                  IN INT height,
627                  IN PixelFormat format);
628    Bitmap* Clone(IN const RectF& rect,
629                  IN PixelFormat format);
630    Bitmap* Clone(IN REAL x,
631                  IN REAL y,
632                  IN REAL width,
633                  IN REAL height,
634                  IN PixelFormat format);
635
636    Status LockBits(IN const Rect& rect,
637                    IN UINT flags,
638                    IN PixelFormat format,
639                    OUT BitmapData* lockedBitmapData);
640    Status UnlockBits(IN BitmapData* lockedBitmapData);
641    Status GetPixel(IN INT x,
642                    IN INT y,
643                    OUT Color *color);
644    Status SetPixel(IN INT x,
645                    IN INT y,
646                    IN const Color &color);
647    Status SetResolution(IN REAL xdpi,
648                         IN REAL ydpi);
649
650    // GDI interop:
651
652    Bitmap(IN IDirectDrawSurface7* surface);
653    Bitmap(IN const BITMAPINFO* gdiBitmapInfo,
654           IN VOID* gdiBitmapData);
655    Bitmap(IN HBITMAP hbm,
656           IN HPALETTE hpal);
657    Bitmap(IN HICON hicon);
658    Bitmap(IN HINSTANCE hInstance,
659           IN const WCHAR * bitmapName);
660    static Bitmap* FromDirectDrawSurface7(IN IDirectDrawSurface7* surface);
661    static Bitmap* FromBITMAPINFO(IN const BITMAPINFO* gdiBitmapInfo,
662                                  IN VOID* gdiBitmapData);
663    static Bitmap* FromHBITMAP(IN HBITMAP hbm,
664                               IN HPALETTE hpal);
665    static Bitmap* FromHICON(IN HICON hicon);
666    static Bitmap* FromResource(IN HINSTANCE hInstance,
667                                IN const WCHAR * bitmapName);
668
669    Status GetHBITMAP(IN const Color& colorBackground,
670                      OUT HBITMAP *hbmReturn);
671    Status GetHICON(HICON *hicon);
672
673#ifdef DCR_USE_NEW_250932
674private:
675    Bitmap(const Bitmap &);
676    Bitmap& operator=(const Bitmap &);
677#endif
678
679protected:
680    Bitmap(GpBitmap *nativeBitmap);
681};
682
683class CustomLineCap : public GdiplusBase
684{
685public:
686    friend class Pen;
687
688    CustomLineCap(
689        IN const GraphicsPath* fillPath,
690        IN const GraphicsPath* strokePath,
691        IN LineCap baseCap = LineCapFlat,
692        IN REAL baseInset = 0
693        );
694    virtual ~CustomLineCap();
695
696    CustomLineCap* Clone() const;
697
698    Status SetStrokeCap(IN LineCap strokeCap)
699    {
700        // This changes both start and and caps.
701
702        return SetStrokeCaps(strokeCap, strokeCap);
703    }
704
705    Status SetStrokeCaps(IN LineCap startCap,
706                         IN LineCap endCap);
707    Status GetStrokeCaps(OUT LineCap* startCap,
708                         OUT LineCap* endCap) const;
709    Status SetStrokeJoin(IN LineJoin lineJoin);
710    LineJoin GetStrokeJoin() const;
711    Status SetBaseCap(IN LineCap baseCap);
712    LineCap GetBaseCap() const;
713    Status SetBaseInset(IN REAL inset);
714    REAL GetBaseInset() const;
715    Status SetWidthScale(IN REAL widthScale);
716    REAL GetWidthScale() const;
717
718protected:
719    CustomLineCap();
720
721#ifdef DCR_USE_NEW_250932
722
723private:
724    CustomLineCap(const CustomLineCap &);
725    CustomLineCap& operator=(const CustomLineCap &);
726protected:
727
728#else
729
730    CustomLineCap(const CustomLineCap& customLineCap)
731    {
732        customLineCap;
733        SetStatus(NotImplemented);
734    }
735
736    CustomLineCap& operator=(const CustomLineCap& customLineCap)
737    {
738        customLineCap;
739        SetStatus(NotImplemented);
740        return *this;
741    }
742
743#endif
744
745    CustomLineCap(GpCustomLineCap* nativeCap, Status status)
746    {
747        lastResult = status;
748        SetNativeCap(nativeCap);
749    }
750
751    VOID SetNativeCap(GpCustomLineCap* nativeCap)
752    {
753        this->nativeCap = nativeCap;
754    }
755
756    Status SetStatus(Status status) const
757    {
758        if (status != Ok)
759            return (lastResult = status);
760        else
761            return status;
762    }
763
764protected:
765    GpCustomLineCap* nativeCap;
766    mutable Status lastResult;
767};
768
769class CachedBitmap : public GdiplusBase
770{
771    friend Graphics;
772
773public:
774    CachedBitmap(IN Bitmap *bitmap,
775                 IN Graphics *graphics);
776    virtual ~CachedBitmap();
777
778    Status GetLastStatus() const;
779
780#ifdef DCR_USE_NEW_250932
781
782private:
783    CachedBitmap(const CachedBitmap &);
784    CachedBitmap& operator=(const CachedBitmap &);
785
786#endif
787
788protected:
789    GpCachedBitmap *nativeCachedBitmap;
790    mutable Status lastResult;
791};
792
793#endif  // !_GDIPLUSHEADERS.HPP
794